package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.TreeMenuMapper;
import com.ghck.server.model.TreeMenu;
import com.ghck.server.model.query.TreeMenuQuery;
import com.ghck.server.service.TreeMenuService;

/**
 * 菜单表  <br>
 * t_tree_menu <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class TreeMenuServiceImpl implements TreeMenuService {
	 
	private static final Logger logger = LoggerFactory.getLogger(TreeMenuServiceImpl.class);
	 
	@Autowired
	private TreeMenuMapper treeMenuMapper;
	
	/**
 	*根据ID删除 菜单表
 	*/
 	@Override
 	public Integer deleteTreeMenuById(Integer id){
 		return treeMenuMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 菜单表
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertTreeMenu(List<? extends TreeMenu> treeMenus){
		Integer count = treeMenuMapper.batchInsert(treeMenus);
		return count;
 	}
 	/**
 	*新增 菜单表
 	*/
 	@Override
 	@Transactional
 	public Integer insertTreeMenu(TreeMenu domain){
		Integer id = treeMenuMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 菜单表
 	*/
 	@Override
 	@Transactional
 	public Integer updateTreeMenu(TreeMenu domain){
		Integer count = treeMenuMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 菜单表
 	*/
 	public TreeMenu findTreeMenuById(Integer id){
 		TreeMenu result = treeMenuMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 菜单表
 	*/
	public List<TreeMenu> findTreeMenuByQuery(TreeMenuQuery query){
		query.dealWith();
		List<TreeMenu> result = treeMenuMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TreeMenu treeMenu : result) {
				treeMenu.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countTreeMenuByQuery(TreeMenuQuery query){
 		query.dealWith();
 		Integer result = treeMenuMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<TreeMenu> findTreeMenuByIds(List<Integer> ids){
 		List<TreeMenu> result = treeMenuMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TreeMenu treeMenu : result) {
				treeMenu.dealWith();
			}
		}
		return result;
 	}
 	
}	